import { Color } from 'cc';
import { Vec3 } from 'cc';
import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

export default class Design {
    // 六边形放置的宽高
    static panelWidth: number = 2
    static panelHeight: number = 1.8
    
    // 拖拽时候的高度
    static dragFloorHeight: number = 2

    static colors = [
        new Color(0xFFFFE91A), new Color(0xFFFF9512), new Color(0xFFFF1F1F), 
        new Color(0xFF2BD341), new Color(0xFF02A3FF), new Color(0xFF631BFF), 
        new Color(0xFFC646FF), new Color(0xFFDDDDDD), new Color(0xFF66696D), 
        new Color(0xFF00581E), new Color(0xFF6A0050), new Color(0xFFFF99CA), 
        new Color(0xFF6F2000), new Color(0xFF5DFF57), new Color(0xFF57FFCC), 
    ]

    static brickConfig = {
        // 六边形块的间隔
        brickSpace: 0.3,
        // 六边形飞行的间隔时间
        brickFlyIntervalDuration: 0.1,
        // 六边形飞行的动画时间
        brickFlyDuration: 0.5,
        // 不同塔间隔时间
        towerIntervalDuration: 0.3,
        // 块缩小间隔时间
        brickCleanIntervalDuration: 0.1,
        // 块缩小时间
        brickCleanDuration: 0.04,
        // 缩小后暂停时间
        brickScaleWaitingDuration: 0.1,
    }
    
    // 移动到其他的父节点，同时保持在屏幕上的位置不变
    public static changeParenWithoutMove(node: Node, newParent: Node) {
        // 获取目标节点的世界坐标
        const worldPosition = new Vec3();
        node.getWorldPosition(worldPosition);

        // 将目标节点设置为新的父节点的子节点
        node.setParent(newParent);

        // 将世界坐标转换为新的父节点的局部坐标
        const localPosition = new Vec3();
        if (newParent != null)
            newParent.inverseTransformPoint(localPosition, worldPosition);

        // 设置目标节点的局部坐标
        node.setPosition(localPosition);
    }

    // 获取一个节点相对于另一个节点的位置
    public static getRelativePosition(source: Node, target: Node): Vec3 {
        // 获取 source 节点的世界坐标
        const worldPosition = new Vec3();
        source.getWorldPosition(worldPosition);

        // 将世界坐标转换为 target 节点的局部坐标
        const localPosition = new Vec3();
        target.inverseTransformPoint(localPosition, worldPosition);

        return localPosition;
    }
}
